<template>
  <div :class="$style.wrap">
    <Title :title="title" :title-class="$style.title" style="padding-top:10px"></Title>
    <table-box ref="table" :table-height="200" :other-filters="otherFilters" no-request :table-config="tableConfig"></table-box>
  </div>
</template>
<script>
import Title from '@/components/Title'
import { filtersRaw, deepCopy } from '@/utils'
export default {
  name: 'CareRable',
  components: {
    Title
  },
  props: {
    businessCode: {
      type: [String, Number],
      default: undefined
    },
    title: {
      type: String,
      default: ''
    },
    type: {
      type: String,
      default: ''
    },
    info: {
      type: Object,
      default: undefined
    }
  },
  data() {
    return {
      tableConfig: {},
      otherFilters: [],
      smsTableConfig: {
        interfacePath: '/call-center/api/v1/smsSendRecord/page',
        hideFuncBar: true,
        setting: [
          {
            label: '序号',
            width: '80',
            align: 'center',
            formatData: v => v.keyIndex + 1
          },
          {
            label: '号码',
            width: 130,
            prop: 'phone'
          },
          {
            label: '是否定时',
            width: 100,
            prop: 'isTiming',
            formatData: v => v.isTiming === 1 || v.isTiming === '1' ? '是' : '否'
          },
          {
            label: '发送时间',
            width: 140,
            prop: 'sendDate'
          },
          {
            label: '短信内容',
            prop: 'content'
          }
        ]
      },
      emailTableConfig: {
        interfacePath: '/call-center/api/v1/emailRecord/page',
        hideFuncBar: true,
        setting: [
          {
            label: '序号',
            width: '80',
            align: 'center',
            formatData: v => v.keyIndex + 1
          },
          {
            label: '收件人',
            width: 160,
            prop: 'emailAddress',
            formatData: v => {
              return v.tos.map(e => e.emailAddress).join(',')
            }
          },
          {
            label: '正文',
            prop: 'content'
          },
          {
            label: '发送时间',
            width: 140,
            prop: 'sendDate'
          }
        ]
      },
      callTableConfig: {
        interfacePath: '/call-center/api/v1/callLog/page',
        hideFuncBar: true,
        setting: [
          {
            label: '序号',
            width: '80',
            align: 'center',
            formatData: v => v.keyIndex + 1
          },
          {
            label: '号码',
            width: 160,
            prop: 'customerPhone'
          },
          {
            label: '通话记录',
            prop: 'callCode'
          },
          {
            label: '呼出时间',
            width: 160,
            prop: 'callDate'
          }
        ]
      },
      giftTableConfig: {
        interfacePath: '',
        hideFuncBar: true,
        setting: [
          {
            label: '序号',
            width: '80',
            align: 'center',
            formatData: v => v.keyIndex + 1
          },
          {
            label: '生日核对',
            width: 140,
            prop: 'checkInfo',
            propEnum: {
              domainCode: 'marketing',
              appCode: 'call-center',
              dictTypeCode: 'KQ_BIRTHDAY_CHECK'
            }
          },
          {
            label: '礼物名称',
            width: 140,
            prop: 'giftName'
          },
          {
            label: '礼物数量',
            width: 100,
            prop: 'quantity'
          },
          {
            label: '快递单号',
            width: 140,
            prop: 'expressNo'
          },
          {
            label: '发放日期',
            width: 140,
            prop: 'sendDate'
          },
          {
            label: '签收人',
            width: 120,
            prop: 'consignee'
          },
          {
            label: '备注',
            width: 120,
            prop: 'remarks'
          },
          {
            label: '默认收货地址',
            width: 160,
            prop: 'defaultAddress'
          },
          {
            label: '客情收货地址',
            width: 160,
            prop: 'address'
          }
        ]
      }
    }
  },
  computed: {
  },
  watch: {
    businessCode: {
      handler: 'genOtherFilters',
      immediate: true
    },
    info: {
      handler: 'setTableData',
      immediate: true
    },
    tableConfig: {
      handler() {
        this.tableConfig = this[`${this.type}TableConfig`] || {}
      },
      immediate: true
    }
  },
  mounted() {
    this.setTableData()
  },
  methods: {
    genOtherFilters() {
      if (!this.businessCode || this.info !== undefined) {
        return
      }
      this.otherFilters = [filtersRaw('businessCode', this.businessCode, '=')]
      this.refresh()
    },
    setTableData() {
      if (this.info !== undefined && this.info.careTaskGiftList !== undefined && this.info.careTaskGiftList.length >= 1) {
        const table = this.$refs.table
        if (!table) return
        const data = deepCopy(this.info.careTaskGiftList)
        for (const item of data) {
          item.defaultAddress = this.info.defaultAddress
          item.remarks = this.info.remarks
          item.consignee = this.info.consignee
          item.checkInfo = this.info.checkInfo
          item.address = `${this.info.provinceName || ''}${this.info.cityName || ''}${this.info.countyName || ''}${this.info.streetName || ''}${this.info.detailAddress || ''}`
        }
        this.$set(table, 'tableData', data)
      }
    },
    refresh() {
      this.$nextTick(() => {
        this.$refs.table.initTableData()
      })
    }
  }
}
</script>
<style lang='scss' module>
.wrap{
.title{
  color: rgba(0,0,0,0.85);
  font-size: 16px;
  font-weight: 700;
}
}
</style>
